from django.db import models
from renranapi.utils.models import BaseModel
# Create your models here.

class Banner(BaseModel):

    name = models.CharField(max_length=150, verbose_name='轮播图标题')
    info = models.CharField(null=True, blank=True, max_length=1000, verbose_name='备注信息')
    link = models.CharField(null=True, blank=True, max_length=150, verbose_name='轮播图广告地址')
    # upload_to 存储子目录，真实存放地址会使用配置中的MADIE_ROOT+upload_to
    image = models.ImageField(upload_to='banner', verbose_name='轮播图', null=True, blank=True)
    start_time = models.DateTimeField(verbose_name="上架时间", default=None, null=True, blank=True)
    end_time = models.DateTimeField(verbose_name="下架时间", default=None, null=True, blank=True)
    is_http = models.BooleanField(verbose_name="是否站外地址", default=False,
                                  help_text="站内地址格式：/users/<br>站外地址格式：http://www.baidu.com")

    class Meta:

        db_table = 'rr_banner'
        verbose_name ='轮播图'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

class Nav(BaseModel):

    POSITION = (
        (1, "头部导航"),
        (2, "脚部导航"),
    )
    pid = models.ForeignKey("Nav", related_name="son", null=True, blank=True, on_delete=models.DO_NOTHING,
                            verbose_name="父亲导航")
    name = models.CharField(max_length=150, verbose_name='导航名称')
    icon = models.CharField(max_length=150, verbose_name="icon图标", help_text="这里填写的是样式名称.")
    link = models.CharField(null=True, blank=True, max_length=150, verbose_name='导航地址')
    position = models.IntegerField(choices=POSITION, default=1, verbose_name="导航位置")
    is_http = models.BooleanField(verbose_name="是否站外地址", default=False,
                                  help_text="站内地址格式：/users/<br>站外地址格式：http://www.baidu.com")

    class Meta:
        db_table = 'rr_nav'
        verbose_name = '导航菜单'
        verbose_name_plural = verbose_name  # 复数

    def __str__(self):
        return self.name